﻿using GWB.Core.Enum;
using System.Collections.Generic;
using System.Linq;

namespace GWB.Core.Common.Entity
{
    /// <summary>
    /// consul 信息
    /// </summary>
    public   class CurrentConsul
    {
        /// <summary>
        /// Consul里面所有服务
        /// </summary>
        public static List<ServiceInfo> ServiceInfos{ get; set; }

        /// <summary>
        /// 单个服务
        /// </summary>
        /// <param name="service"></param>
        /// <returns></returns>
        public static ServiceInfo ConsulInfo(ConsulService service)
        {
            //TODO:使用负载均衡还是其他什么策略
           return ServiceInfos.FirstOrDefault(x => x.Service == service.ToString());
        }
    }

  public class ServiceInfo
    {
        /// <summary>
        /// 服务
        /// </summary>
      public string Service { get; set; }

        public string Address { get; set; }

        public int Port { get; set; }
        

        public string Url
        {
            get { return $"http://{Address}:{Port}"; }
        }

  }
}
